package com.briup.bms.web.controller;

import com.briup.bms.bean.SCustomer;
import com.briup.bms.common.utils.Result;
import com.briup.bms.service.SCustomerService;
import com.briup.bms.web.vm.DeptParamVM;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Set;

/**
 * @author: Paocha
 * @date: 2021-11-23-14:41
 */
@Api(tags = "顾客服务")
@RestController
@RequestMapping("/customer")
public class CustomerController {

    private final SCustomerService customerService;


    public CustomerController(SCustomerService customerService) {
        this.customerService = customerService;
    }

    @ApiOperation(value = "按条件分页显示客户信息")
    @GetMapping("/by/condition")
    public Result<PageInfo<SCustomer>> findByCondition(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize,
            String name) {

        return Result.success(customerService.findByConditon(
                pageNum, pageSize, name));
    }

    @GetMapping()
    public Result<PageInfo<SCustomer>> findByPageHelper(
            @RequestParam(defaultValue = "1") int pageNum,
            @RequestParam(defaultValue = "5") int pageSize) {

        return Result.success(customerService.findByPageHelper(
                pageNum, pageSize));
    }

    @PostMapping
    public Result<String> saveOrUpdate(@RequestBody SCustomer customer) {
        //业务处理
        customerService.saveOrUpdate(customer);
        return Result.success("操作id为"+customer.getId()+"成功！");
    }

    @DeleteMapping("/{customerId}")
    public Result<String> deleteCustomer(@PathVariable("customerId") Integer customerId) {
        customerService.deleteCustomer(customerId);
        return Result.success("删除"+customerId+"成功");
    }
    @DeleteMapping("/batchDelete")
    public Result<String> batchDeleteCustomer(@RequestParam("customerIds") Set<Integer> customerIds) {
        customerService.batchDeleteCustomer(customerIds);
        return Result.success("删除"+ customerIds +"成功");
    }
}
